package com.example.ecmftlutil;

import java.util.ArrayList;
import java.util.List;

public class DataPrint {

    public static void print(Test.Node node, List<String> onlineCode) {
        if (null == node) {
            return;
        }
        if (node.getChildren().size() == 0) {
            // 上线数据需要输出
            if(onlineCode.contains(node.getCode())){
                System.out.println(node.getCode() + ": [" + node.getCode() + "]");
            }
        }

        List<String> result = new ArrayList<>();
        getLeafNodes(node, result);
        System.out.println(node.getCode() + ":" + result);
        for (Test.Node child : node.getChildren()) {
            print(child, onlineCode);
        }
    }

    private static void getLeafNodes(Test.Node node, List<String> result) {
        if (null == node) {
            return;
        }
        if (node.getChildren().size() == 0) {
            result.add(node.getCode());
            return;
        }
        for (Test.Node child : node.getChildren()) {
            getLeafNodes(child, result);
        }
    }

    private static void getLeafNodes1(Test.Node node, List<Test.Node> result) {
        if (null == node) {
            return;
        }
        if (node.getChildren().size() != 0) {
            result.addAll(node.getChildren());

        }
        for (Test.Node child : node.getChildren()) {
            getLeafNodes1(child, result);
        }
    }

}
